%%
%（1）
photo_path = './photo.png';
img = imread(photo_path);

% Extract R, G, B channels
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);

% Convert RGB to HSI
hsi_img = rgb2hsi(img);

% Extract H, S, I channels
H = hsi_img(:,:,1);
S = hsi_img(:,:,2);
I = hsi_img(:,:,3);

% Display the results
figure;
subplot(2,4,1), imshow(img), title('Original Image');
subplot(2,4,2), imshow(R), title('Red Channel');
subplot(2,4,3), imshow(G), title('Green Channel');
subplot(2,4,4), imshow(B), title('Blue Channel');
subplot(2,4,5), imshow(hsi_img), title('HSI Image');
subplot(2,4,6), imshow(H), title('Hue Channel');
subplot(2,4,7), imshow(S), title('Saturation Channel');
subplot(2,4,8), imshow(I), title('Intensity Channel');

%%
%（2）
% Read the color image
photo_path = './photo1.jpg';
img = imread(photo_path);

% Convert to grayscale
gray_img = rgb2gray(img);

% Edge detection using Prewitt operator
prewitt_edges = edge(gray_img, 'Prewitt');

% Edge detection using Canny operator
canny_edges = edge(gray_img, 'Canny');

% Edge detection using LOG operator
log_edges = edge(gray_img, 'log');

% Display the results
figure;
subplot(2,2,1), imshow(gray_img), title('灰度图');
subplot(2,2,2), imshow(prewitt_edges), title('Prewitt算子');
subplot(2,2,3), imshow(canny_edges), title('Canny算子');
subplot(2,2,4), imshow(log_edges), title('LOG算子');

%%
%（3）
% Read the color image
photo_path = './photo1.jpg';
img = imread(photo_path);

% Convert to grayscale
gray_img = rgb2gray(img);

% Extract corners using Harris corner detector with different thresholds
corners_001 = corner(gray_img, 'Harris', 'SensitivityFactor', 0.01);
corners_002 = corner(gray_img, 'Harris', 'SensitivityFactor', 0.02);

% Display the results
figure;
subplot(1,3,1), imshow(gray_img), title('灰度图');
hold on;
plot(corners_001(:,1), corners_001(:,2), 'r*');
title('阈值为 0.01 的角点');
hold off;

subplot(1,3,2), imshow(gray_img), title('灰度图');
hold on;
plot(corners_002(:,1), corners_002(:,2), 'g*');
title('阈值为 0.02 的角点');
hold off;

subplot(1,3,3), imshow(gray_img), title('灰度图');
hold on;
plot(corners_001(:,1), corners_001(:,2), 'r*');
plot(corners_002(:,1), corners_002(:,2), 'g*');
title('角点的比较');
hold off;

%%
%（4）
% Read the color image
photo_path = './photo1.jpg';
img = imread(photo_path);

% Convert to grayscale
gray_img = rgb2gray(img);

% Extract SURF features
points = detectSURFFeatures(gray_img);

% Sort points by metric (strength)
sorted_points = points.selectStrongest(10);

% Display the results
figure;
imshow(gray_img), title('灰度图');
hold on;
plot(sorted_points);
title('强度前十的特征点');
hold off;

%%
%（5）
% Read the color image
photo_path = './photo1.jpg';
img = imread(photo_path);

% Convert to grayscale
gray_img = rgb2gray(img);

% Calculate GLCM features
glcm = graycomatrix(gray_img);
stats = graycoprops(glcm, {'contrast', 'correlation', 'energy', 'homogeneity'});

% Calculate LBP features
lbp_features = extractLBPFeatures(gray_img);

% Calculate GMRF features (assuming gmrf is a custom function)
gmrf_features = gmrf(gray_img);

% Calculate Gabor filter features (assuming Gabor_extract is a custom function)
gabor_features = Gabor_extract(gray_img);

% Display the results
figure;
subplot(2,3,1), imshow(img), title('原图');
subplot(2,3,2), imshow(gray_img), title('灰度图');
subplot(2,3,3), imshow(glcm, []), title('GLCM 特征');
subplot(2,3,4), bar(lbp_features), title('LBP 特征');
subplot(2,3,5), bar(gmrf_features), title('GMRF 特征');
subplot(2,3,6), bar(gabor_features), title('Gabor 特征');









